#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

int n;
string str1, str2;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    int T;
    cin >> T;
    while(T--){
        cin >> n >> str1 >> str2;
        for(int i = 0; i < n; i ++){
            if(str1[i] == 'B') str1[i] = 'G';
            if(str2[i] == 'B') str2[i] = 'G';
        }

        if(str1.find(str2) != string::npos){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }

    return 0;
}